#ifndef __MYDICT_H_
#define __MYDICT_H_
#include "SplitToolCppJieba.hpp"
#include "MyTask.h"
#include "DictProducer.h"
#include "Configuration.h"
#include "../net/Mutexlock.h"
#include <vector>
#include <string>
#include <map>
#include <set>
#include <iostream>
#include <fstream>
#include <queue>
#include <sstream>
using std::ifstream;
using std::ofstream;
using std::stringstream;
using std::map;
using std::pair;
using std::set;
using std::string;
using std::vector;
using std::priority_queue;

namespace SC
{
    struct MyResult;
    struct MyCompare;
    
    class MyDict
    {
    public:
        static MyDict *getpInstance();
        static void destroy();

        void query(
            const string &queryWord, 
            priority_queue<MyResult, 
            vector<MyResult>, MyCompare> &priQueue);

        //第一次读取语料库
        void initDict(
            const string &en_dir, 
            const string &ch_dir, 
            const string &en_dict_path, 
            const string &ch_dict_path, 
            const string &cache_dir); 

        void initDict(const string &cache_dir);                                                              

    private:
        MyDict() {}
        ~MyDict() {}
        vector<string> divide(const string &str);
        int min(int a, int b, int c);
        int editDistance(const string &str1, const string &str2);
        void writeToCache(const string &file);
        void readFromCache(const string &file);

    private:
        static MyDict *_pInstance;
        vector<pair<string, int>> _dict; //<单词，词频>
        map<string, set<int>> _indexMap; //<单个中英文字符，该字符出现在_dict中的下标集合>
        Mutexlock _mutexlock;  
    };
}

#endif